

# Create your models here.
# organization/py

from datetime import datetime

from django.db.models import *


# class CityDict(Model):
#     is_del = IntegerField(default=0)
#     name = CharField('城市',max_length=20)
#     level = IntegerField()
#     upid = IntegerField()
#
#     class Meta:
#         verbose_name = '三级城市'
#         verbose_name_plural= verbose_name
#
#     def __str__(self):
#         return "->>{0}".format(self.name)


class CourseOrg(Model):
    is_del = IntegerField(default=0)
    ORG_CHOICES = (
        ("pxjg", u"培训机构"),
        ("gx", u"高校"),
        ("gr", u"个人"),
    )
    name = CharField('机构名称',max_length=50)
    desc = TextField('机构描述')
    click_nums = IntegerField('点击数', default=0)
    category = CharField(max_length=20, choices=ORG_CHOICES, verbose_name=u"机构类别", default="pxjg")

    fav_nums = IntegerField('收藏数',default=0)
    image = ImageField('logo',upload_to='org/%Y%m',max_length=100)
    address = CharField('机构地址',max_length=200)
    # city = ForeignKey(CityDict,verbose_name='所在城市',on_delete=CASCADE)
    # 冗余字段
    order_num = IntegerField('机构的订单数',default=0)
    money = DecimalField("机构的总钱数",default=0,max_digits = 10,decimal_places = 2)
    teacher_num = IntegerField("机构的老师数量",default=0)
    add_time = DateTimeField(default=datetime.now)

    class Meta:
        verbose_name = '课程机构'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Teacher(Model):
    is_del = IntegerField(default=0)
    org = ForeignKey(CourseOrg,verbose_name='所属机构',on_delete=CASCADE)
    name = CharField('教师名',max_length=50)
    work_years = IntegerField('工作年限',default=0)
    work_company = CharField('就职公司',max_length=50)
    work_position = CharField('公司职位',max_length=50)
    points = CharField('教学特点',max_length=50)
    click_nums = IntegerField('点击数',default=0)
    fav_nums = IntegerField('收藏数',default=0)
    add_time = DateTimeField(default=datetime.now)

    class Meta:
        verbose_name = '教师'
        verbose_name_plural = verbose_name

    def __str__(self):
        return "[{0}]的教师: {1}".format(self.org, self.name)

class OrgManager(Model):
    is_del = IntegerField(default=0)
    username = CharField('机构用户名',max_length=50)
    password = CharField('机构密码',max_length=100)
    address = CharField('地址', max_length=200, default='')
    # province_id = ForeignKey(CityDict,verbose_name='省id',on_delete=CASCADE)
    # city_id = ForeignKey(CityDict,verbose_name='市id',on_delete=CASCADE)
    # area_id = ForeignKey(CityDict,verbose_name='区域id',on_delete=CASCADE)
    org = ForeignKey(CourseOrg,verbose_name='所属机构',on_delete=CASCADE)
    mobile = CharField('手机号',max_length=11)
    add_time = DateTimeField(default=datetime.now)

    class Meta:
        verbose_name = '机构管理员'
        verbose_name_plural = verbose_name

    def __str__(self):
        return "{1}".format(self.name)